<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>险种添加</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<style type="text/css">
.input_text{
width: 250px;
}
.select_1{
width: 250px;
}
</style>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>


<script type="text/javascript">
var startP=1;
var startPlan=1;
var startCov=1;
var tradProdCode='${tradProdCode}';

var chooseTradPlanCode="";
var chooseAmount="";
var required="";
var etradPlanCode="";
var isHealthFlag="";

var Formstatus=true;

//自定义map功能
/*---------------------Map 构造开始---------------------------------*/
function Map(){
   this.elements = new Array();
   //获取MAP元素个数
   this.size = function() {
       return this.elements.length;
   };
   //判断MAP是否为空
   this.isEmpty = function() {
       return (this.elements.length < 1);
   };
   //删除MAP所有元素
   this.clear = function() {
       this.elements = new Array();
   };
   //向MAP中增加元素（key, value)
   this.put = function(_key, _value) {
       if(this.containsKey(_key)){
        this.remove(_key);
        this.elements.push( {
           key : _key,
           value : _value
        });
       }else{
        this.elements.push( {
           key : _key,
           value : _value
        });
       }  
   };
   //删除指定KEY的元素，成功返回True，失败返回False
   this.remove = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   this.elements.splice(i, 1);
                   return true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
   //获取指定KEY的元素值VALUE，失败返回NULL
   this.get = function(_key) {
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   return this.elements[i].value;
               }
           }
       } catch (e) {
           return "";
       }
       return "";
   };
   //判断MAP中是否含有指定KEY的元素
   this.containsKey = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   bln = true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
  //获取map的所有values
  this.values = function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].value);
       }
       return arr;
   };
  //获取map的所有keys
  this.keys= function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].key);
       }
       return arr;
   };
   //获取数组
   this.getArray= function(){
   	var arr = new Array();
   	for (var i = 0; i < this.elements.length; i++) {
           arr.push({
	            key : this.elements[i].key,
	            value : this.elements[i].value
	         });
       }
       return arr;
   };
};
/*---------------------Map 构造完成---------------------------------*/

$(document).ready(function() {
	
	var poolTypeVal = ${poolType};
	//判断产品共保选项是否为”险种级共保“，如果是则显示”共保份额“且必填；否则不显示该字段。
	if(poolTypeVal == 2){
		$("#lastTr").after("<tr><th>共保份额：</th><td colspan='3'><input id='poolRatio' type='text' class='input_text'>&nbsp;<span style='font-size:16px;vertical-align:middle;'>%</span><span class='red'>*</span></td></tr>");

		var $poolRatio = $("#poolRatio");
		$poolRatio.change(function(){
		var regRatio = new RegExp("^([1-9][0-9]?|100)$");
		    if(!regRatio.test($poolRatio.val())){
		    	$.message("error","请输入0-100的有效整数");
		    	return;
		    }
		});
	}
	
	checkCalDef('calDefId','Amount');
	
	loadPlan({current:1,size:6,tradProdCode:tradProdCode});
});


//检查“算法定义”，校验是否允许输入保额
function checkCalDef(cal,amt){
	var calDef = $('#'+cal).val();
	/* if(calDef=="0000000005"||calDef=="0000000006"||calDef=="0000000007"){
		$('#'+amt).val('');
		$('#'+amt).attr('readonly',true);
		$('#'+amt).css('background-color',"#ccc");
	}else{
		$('#'+amt).attr('readonly',false);
		$('#'+amt).css('background-color',"white");
	} */
	loadChildCal(cal);//查询是否有子算法
}
function checkeCalDef(cal,amt,calId){
	var calDef = $('#'+cal).val();
	/* if(calDef=="0000000005"||calDef=="0000000006"||calDef=="0000000007"){
		$('#'+amt).val('');
		$('#'+amt).attr('readonly',true);
		$('#'+amt).css('background-color',"#ccc");
	}else{
		$('#'+amt).attr('readonly',false);
		$('#'+amt).css('background-color',"white");
	} */
	loadeChildCal(cal,calId);//查询是否有子算法
}

function bindradio(){
	$("input[name='radioPlan']").click(function(){
		$("input[name='radioPlan']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}

function bindradio2(){
	$("input[name='radioProPlan']").click(function(){
		$("input[name='radioProPlan']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}

function loadTempPlan(param){
	$.openLoading();
	$.ajax({
		url : "product/loadProdPlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			
			startPlan = page.current;
			var firstbutton ="<input class='input_fxk' name='radioPlan' type='radio' value=''>";
			var tableContent = creatTable1("prodInstCode@TDH,insType@TDH,required@TDH,planCode,instCode,insnme,isHealthFlag@TDH",page,firstbutton,null);
			var tableObj = $("#productPlanTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage(startPlan,6,page.maxPage,"12");
			var pageDIV = $("#productPlanpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			bindradio();
			$("#addPlanDiv").OpenDiv();
		}
	});
}
function loadPlan(param){
	$.openLoading();
	$.ajax({
		url : "product/loadPlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			
			startP = page.current;
			var firstbutton ="<input class='input_fxk' name='radioProPlan' type='radio' value=''>";
			var lastbutton = "<a href='javascript:void(this)' id='e{TRADPLANCODE}' onClick='editProPlan({TRADPLANCODE},this);'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='deleteplan({TRADPLANCODE},this);'>删除</a>";

			var tableContent = creatTable2("tradPlanCode,tradPlanDesc,amount,planCode,insnme,calDefId@TDH,poolRatio@TDH,instCod@TDH,calId@TDH,isHealthFlag@TDH",page,firstbutton,lastbutton);
			var tableObj = $("#ProdPlanTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage3(startP,6,page.maxPage,"13");
			var pageDIV = $("#ProdPlanpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			bindradio2();
		}
	});
}



function queryProdPlan(pagenum){
	loadPlan({current:pagenum,size:6,tradProdCode:tradProdCode});
}

function addPlan(param){
	if(!Formstatus){
		$.message("error","正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "product/savePlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			//表单状态
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			vreset();
			loadPlan({current:1,size:6,tradProdCode:tradProdCode});
		}
	});
}

function clearNoNum(event,obj){ 
    //响应鼠标事件，允许左右方向键移动 
    event = window.event||event; 
    if(event.keyCode == 37 | event.keyCode == 39){ 
        return; 
    } 
    //先把非数字的都替换掉，除了数字和. 
    obj.value = obj.value.replace(/[^\d.]/g,""); 
    //必须保证第一个为数字而不是. 
    obj.value = obj.value.replace(/^\./g,""); 
    //保证只有出现一个.而没有多个. 
    obj.value = obj.value.replace(/\.{2,}/g,"."); 
    //保证.只出现一次，而不能出现两次以上 
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
} 
function checkNum(obj){ 
    //为了去除最后一个. 
    obj.value = obj.value.replace(/\.$/g,""); 
}

//添加险种
function add(){
	var planCode= $("#planCode").val();
	var tradPlanDesc= $.trim($("#tradPlanDesc").val());
	if(planCode.length==0){
		$.message("error","请选择险种模板");
    	return;
	}

	if(tradPlanDesc.length==0){
		$.message("error","请输入险种名称");
    	return;
	}

	var calDefId = $('#calDefId').val();
	var Amount= $.trim($("#Amount").val());
	if(calDefId!="0000000005"&&calDefId!="0000000006"&&calDefId!="0000000007"){
		if(calDefId!="0000000002"){
			if(Amount.length==0){
				$.message("error","请输入险种保额");
		    	return;
			}
		    //小数点. 后面只能保留2位小数
		    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
		    var flag= reg.test(Amount);
		    if(!flag){
		    	$.message("error","输入金额最多保留2位小数");
		    	return;
		    }
		    //没有小数点情况下，输入金额长度不能超过8位数字
		    var strval = Amount+"";
		    var idx = strval.indexOf('.');
		    if(idx==-1){
		    	if(strval.length>8){
		    		$.message("error","输入金额长度不能超过8位数字");
		    		return;
		    	}
		    }
		}else{
			if(Amount.length!=0){
		    //小数点. 后面只能保留2位小数
		    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
		    var flag= reg.test(Amount);
		    if(!flag){
		    	$.message("error","输入金额最多保留2位小数");
		    	return;
		    }
		    //没有小数点情况下，输入金额长度不能超过8位数字
		    var strval = Amount+"";
		    var idx = strval.indexOf('.');
		    if(idx==-1){
		    	if(strval.length>8){
		    		$.message("error","输入金额长度不能超过8位数字");
		    		return;
		    	}
		    }
		}
		}
	}
	var SprodInstCode= $("#prodInstCode").val();
	var SinsType= $("#insType").val();
	var SinstCode= $("#instCode").val();
	var Sinsnme= $("#insnme").val();
	
	
	//共保份额
	var poolTypeVal = ${poolType};
	var poolRatioVal;
	if(poolTypeVal == 2)
	{
		var $poolRatio = $.trim($("#poolRatio").val());
		if($poolRatio.length==0){
	    	$.message("error","请输入共保份额");
	    	return;
		}
		//校验共保份额
	    var regRatio = new RegExp("^([1-9][0-9]?|100)$");
	    if(!regRatio.test($poolRatio)){
	    	$.message("error","请输入0-100的有效整数");
	    	return;
	    }
	    poolRatioVal = $poolRatio;
	}
	
	var calId_val = $("#calId").val();
	

	addPlan({tradProdCode:tradProdCode,planCode:planCode,tradPlanDesc:tradPlanDesc,Amount:Amount,calDefId:calDefId,prodInstCode:SprodInstCode,insType:SinsType,instCode:SinstCode,insnme:Sinsnme,required:required,poolRatio:poolRatioVal,calId:calId_val,isHealthFlag:isHealthFlag});
}
function queryProductPlan(pagenum){
	loadTempPlan({current:pagenum,size:10,tradProdCode:tradProdCode});
}
function choosePlan(){
	var radioTemple = $("input[name='radioPlan']:checked");
	
	var prodInstCode= radioTemple.parent().parent().children(" td:eq(1)").html();
	var insType= radioTemple.parent().parent().children(" td:eq(2)").html();
	var planCode= radioTemple.parent().parent().children(" td:eq(4)").html();
	var instCode= radioTemple.parent().parent().children(" td:eq(5)").html();
	var tradPlanDesc= radioTemple.parent().parent().children(" td:eq(6)").html();
	
	var Vrequired= radioTemple.parent().parent().children(" td:eq(3)").html();
	isHealthFlag = radioTemple.parent().parent().children(" td:eq(7)").html();
	required=Vrequired;
	$("#prodInstCode").val(prodInstCode);
	$("#insType").val(insType);
	$("#planCode").val(planCode);
	$("#instCode").val(instCode);
	$("#tradPlanDesc").val(tradPlanDesc);
	$("#insnme").val(tradPlanDesc);
	closePlanDiv();
}
//补全数据

function openPlanDiv(obj){
	$("#"+obj.id).blur();
	loadTempPlan({tradProdCode:tradProdCode});
}
function closePlanDiv(){
	$("#addPlanDiv").CloseDiv();
}
function openProductList(){
	window.location.href='<%=basePath%>product/list';
}
function openInsurance(){
	window.location.href='<%=basePath%>product/prodPlan?tradProdCode='+tradProdCode;
}

/**
 * 加载责任列表
 */
function loadCoverage(param){
	$.openLoading();
	$.ajax({
		url : "product/coverage",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			
			startCov = page.current;
			var lastbutton = "<input class='input_text' style='width:100px;' maxlength='30' id='{TRADCOVCODE}' name='tradCovName' type='text' value='{TRADCOVNAME}'>@<select name='isInputAmt' onchange='checkAmountisAllowInput(this)' class='select_1' style='visibility: visible;width:130px;'><option value='Y'>固定保额</option><option value='N'>前端传入</option></select>&nbsp;<input class='input_text' style='width:100px;' maxlength='10' name='covAmt' type='text' value='{COVAMT}'>@<input class='input_text' style='width:100px;' maxlength='15' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' name='noCalimAmount' type='text' value='{NOCALIMAMOUNT}'>@<input class='input_text' style='width:100px;' maxlength='5' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' name='claimRate' type='text' value='{CLAIMRATE}'>";
			//var lastbutton = "<select name='isInputAmt' onchange='checkAmountisAllowInput(this)' class='select_1' style='visibility: visible;width:130px;'><option value='Y'>固定保额</option><option value='N'>前端传入</option></select>&nbsp;<input class='input_text' style='width:100px;' maxlength='10' name='covAmt' type='text' value='{COVAMT}'>";
			
			var tableContent = creatTable2("covCode,tradCovCode@TDH,covNme,corecovcode@TDH,tradCovCode,isInputAmount@TDH",page,null,lastbutton);
			var tableObj = $("#coverageTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage2(startCov,6,page.maxPage,"14");
			var pageDIV = $("#coverageTablepageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			
			var covAmt= $("input[name='covAmt']");
			for(var i=0;i<covAmt.length;i++){

				var $amountInput = covAmt.eq(i).parent().parent().children(" td:eq(5)").find('input')
				
				var flag = covAmt.eq(i).parent().parent().children(" td:eq(4)").html();
				if(flag=="N"){
					$($amountInput).attr('readonly',true);
					$($amountInput).css('background-color','#ccc');
					//$($amountInput).val('');
				}else{
					$($amountInput).attr('readonly',false);
					$($amountInput).css('background-color','white');
				}

				var selObj = covAmt.eq(i).parent().parent().children(" td:eq(5)").find('select');
				
				$(selObj).val(flag);

				var tradCovCodeval =covAmt.eq(i).parent().parent().children(" td:eq(0)").html();
				if(chooseAmount=="" && tradCovCodeval==""){
					$($amountInput).css('background-color','#ccc');
					$($amountInput).attr('readonly',true);
					$(selObj).val("N");
				}
/* 				if(chooseAmount=="" && (flag=="" || flag=="N")){
				}
 */				
			}
			
			
			$("#editCovDiv").OpenDiv();
		}
	});
}

//校验是否需要输入保额
function checkAmountisAllowInput(obj){
	var caldefVal = $(obj).val();
	var $amountInput = $(obj).siblings('input');
	if(caldefVal=="N"){
		$($amountInput).attr('readonly',true);
		$($amountInput).css('background-color','#ccc');
		$($amountInput).val('');
	}else{
		$($amountInput).attr('readonly',false);
		$($amountInput).css('background-color','white');
	}
}

function saveCoverage(param){
	if(!Formstatus){
		$.message("error","正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "product/saveCoverage",
		type : 'POST',
		async : true,
		dataType:'json',
		contentType:"application/json",
		data:param, 
		success : function(obj) {
			$.closeLoading();
			Formstatus=true;
			if($.validate(obj))return;
			$("#editCovDiv").CloseDiv();
			
		}
	});
}
/**
 * 保存责任保额
 */
function saveCov(){
	//险种的每条责任的保额均不能大于险种保额，所有责任保额之和与险种保额大小无关。每次必须
	//填写至少一个责任保额，方可保存
	var saveDataAry=[];
	var covAmt= $("input[name='covAmt']");
	var selObj = $("select[name='isInputAmt']");
	var noCalimAmount = $("input[name='noCalimAmount']");
	var claimRate = $("input[name='claimRate']");
	var tradCovNames=$("input[name='tradCovName']");
	
	var tradCovName='';
	var trad_Cov_Code='';
	for(var  i=0;i<tradCovNames.length;i++){
		 tradCovName += tradCovNames.eq(i).val()+";";
		 trad_Cov_Code += tradCovNames.eq(i).attr('id')+";";
	}
	//初始化一个变量，如果用户填了保额每次累加1，如果所有保额均为空，结果即为0，给予提示。
/*	for(var i=0;i<covAmt.length;i++){
		var inputflag =selObj.eq(i).val();
		var covAmtval =covAmt.eq(i).val();
 		if(inputflag=="Y" && covAmtval ==""){
			$.message("error","请输入保额");
			return;
		}
 	}
		*/	
	
	for(var i=0;i<covAmt.length;i++){
		var covAmtval =covAmt.eq(i).val();
		   //小数点. 后面只能保留2位小数
		var noCalimAmountVal = noCalimAmount.eq(i).val();
		var claimRateVal = claimRate.eq(i).val();
		
	    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
		if(covAmtval!=""){
		    var flag= reg.test(covAmtval);
		    if(!flag){
		    	$.message("error","输入金额必须为有效数字且最多保留2位小数");
		    	return;
		    }
		    //没有小数点情况下，输入金额长度不能超过8位数字
		    var strval = covAmtval+"";
		    var idx = strval.indexOf('.');
		    if(idx==-1){
		    	if(strval.length>8){
		    		$.message("error","输入金额长度不能超过8位数字");
		    		return;
		    	}
		    }		
	    
		if(Number(covAmtval)>Number(chooseAmount)){
			$.message("error","输入责任保额不能大于险种保额:"+chooseAmount);
			return;
		}
		
	}
		if(null!=noCalimAmountVal && ""!=noCalimAmountVal){
			 var flag= reg.test(noCalimAmountVal);
			 if(!flag){
			    	$.message("error","输入免赔金额必须为有效数字且最多保留2位小数");
			    	return;
			 }
		}
		var inputflag =selObj.eq(i).val();
		
		var tradCovCodeval =covAmt.eq(i).parent().parent().children(" td:eq(1)").html();
		var coreCovCode = covAmt.eq(i).parent().parent().children(" td:eq(3)").html();
		
		
		
		
		var data={"trad_Cov_Code":trad_Cov_Code,"tradCovName":tradCovName,"tradPlanCode":chooseTradPlanCode,"tradCovCode":tradCovCodeval,"covAmt":covAmtval,"coreCovCode":coreCovCode,"isInputAmount":inputflag,"noCalimAmount":noCalimAmountVal,"claimRate":claimRateVal};
		saveDataAry.push(data);
	}
	//保存责任保额
	saveCoverage(JSON.stringify(saveDataAry));
	
}

var tradPlanCodeCov= '';
var covCodeCov = '';
var instCodeCov= '';
//点击”配置责任“打开责任Div
function openCovDiv(obj){
	$("#"+obj.id).blur();
	var radioCov= $("input[name='radioProPlan']:checked");
	if(radioCov.val()==undefined){
		$.message("error","请选择一个险种");
		return;
	}
	tradPlanCodeCov= radioCov.parent().parent().children(" td:eq(1)").html();
	covCodeCov = radioCov.parent().parent().children(" td:eq(4)").html();
	var amount= radioCov.parent().parent().children(" td:eq(3)").html();
	instCodeCov= radioCov.parent().parent().children(" td:eq(8)").html();

	chooseAmount=amount;//选择的险种的保额
	chooseTradPlanCode=tradPlanCodeCov;
	//根据险种对应的产品代码、业务系统险种代码、险种模板号查询选择的险种下所有责任
	loadCoverage({tradPlanCode:tradPlanCodeCov,covCode:covCodeCov,instCode:instCodeCov});
	
}

function queryCovpage(pagenum){
	loadCoverage({current:pagenum,size:8,tradPlanCode:tradPlanCodeCov,covCode:covCodeCov,instCode:instCodeCov});
};

function closeCovDiv(){
	$("#editCovDiv").CloseDiv();
	var tradPlanCodeCov= '';
	var covCodeCov = '';
	var instCodeCov= '';
}

function closeCalDiv(){
	$('#editCalDiv').CloseDiv();
	$('#calTd').empty();
	$('#calTable').remove();
	$('input[name="tradPlanCode"]').remove();
	$('input[name="calDefId"]').remove();
	$('input[name="childCalDefId"]').remove();
	$('#titleDiv').html('');
}
	

/**
 * 重置
 */
function vreset(){
	$("#insnme").val("");
	$("#tradPlanDesc").val("");
	$("#planCode").val("");
	$("#instCode").val("");
	$("#prodInstCode").val("");
	$("#insType").val("");
	$("#Amount").val("");
	$("#poolRatio").val("");
	isHealthFlag="";
	
}
/**
 * 删除险种
 */
function deleteplan(tradPlanCode,obj){
	var isFlag = $(obj).parent().parent().children(" td:eq(10)").html();
	$.dialog({
		type: "warn",//success,error
		content: "您确定要删除该险种吗？",
		/*重写
		onCancel:function(){
			alert("onCancel:function");
		},
		onClose:function(){
			alert("onClose:function");
		},*/
		onOk: function() {
			delplan(tradPlanCode,isFlag);
		}
	});
}
function delplan(tradPlanCode,isHealthFlag){
	$.openLoading();
	$.ajax({
		url : "product/deletePlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{tradPlanCode:tradPlanCode,tradProdCode:tradProdCode,isHealthFlag:isHealthFlag},
		success : function(obj) {
			$.closeLoading();
			if($.validate(obj))return;
			
			loadPlan({current:1,size:6,tradProdCode:tradProdCode});
		}
	});
}
function editProPlan(tradPlanCode,obj){
	var chooseid=obj.id;
	var tradPlanDesc=  $("#"+chooseid).parent().parent().children(" td:eq(2)").html();
	var amount= $("#"+chooseid).parent().parent().children(" td:eq(3)").html();
	var calDefId= $("#"+chooseid).parent().parent().children(" td:eq(6)").html();
	
	
	var ratio= $("#"+chooseid).parent().parent().children(" td:eq(7)").html();
	
	var calId= $("#"+chooseid).parent().parent().children(" td:eq(9)").html();
	if(ratio!=""){
		$("#ratioPercent").val(Number(ratio)*100);
	}else{
		$("#ratioPercent").val('');
	}
	
	$("#etradPlanDesc").val(tradPlanDesc);
	$("#eAmount").val(amount);
	$("#ecalDefId").find("option[value='"+calDefId+"']").attr("selected",true);  

	checkeCalDef('ecalDefId','eAmount',calId);
	//$("#ecalId").find("option[value='"+calId+"']").attr("selected",true);
	
	etradPlanCode=tradPlanCode;
	$("#editPlanDiv").OpenDiv();
}

//编辑险种
function saveEditPlan(){
	var etradPlanDesc=$.trim($("#etradPlanDesc").val());
	if(etradPlanDesc.length==0){
		$.message("error","交易系统险种名称不能为空");
		return;
	}
	
	var ecalDefId=$("#ecalDefId").val();
	var eAmount=$.trim($("#eAmount").val());
	if(ecalDefId!="0000000005"&&ecalDefId!="0000000006"&&ecalDefId!="0000000007"){
		if(ecalDefId!="0000000002"){
			if(eAmount.length==0){
				$.message("error","险种保额不能为空");
				return;
			}
		    //小数点. 后面只能保留2位小数
		    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
		    var flag= reg.test(eAmount);
		    if(!flag){
		    	$.message("error","输入金额最多保留2位小数");
		    	return;
		    }
		    //没有小数点情况下，输入金额长度不能超过8位数字
		    var strval = eAmount+"";
		    var idx = strval.indexOf('.');
		    if(idx==-1){
		    	if(strval.length>8){
		    		$.message("error","输入金额长度不能超过8位数字");
		    		return;
		    	}
		    }
		}else{
			if(eAmount.length>0){
			    //小数点. 后面只能保留2位小数
			    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
			    var flag= reg.test(eAmount);
			    if(!flag){
			    	$.message("error","输入金额最多保留2位小数");
			    	return;
			    }
			    //没有小数点情况下，输入金额长度不能超过8位数字
			    var strval = eAmount+"";
			    var idx = strval.indexOf('.');
			    if(idx==-1){
			    	if(strval.length>8){
			    		$.message("error","输入金额长度不能超过8位数字");
			    		return;
			    	}
			    }
			}
		}
	}else{
		if(eAmount.length>0){
		    //小数点. 后面只能保留2位小数
		    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
		    var flag= reg.test(eAmount);
		    if(!flag){
		    	$.message("error","输入金额最多保留2位小数");
		    	return;
		    }
		    //没有小数点情况下，输入金额长度不能超过8位数字
		    var strval = eAmount+"";
		    var idx = strval.indexOf('.');
		    if(idx==-1){
		    	if(strval.length>8){
		    		$.message("error","输入金额长度不能超过8位数字");
		    		return;
		    	}
		    }
		}
	}	

    

    //如果当前产品的共保选项为”险种级共保“，则险种编辑页面需要展示“共保份额”，并校验，
	//如果不是“险种级共保”，不显示，不校验
	var rpVal="";
	<%
	Object objptype = request.getAttribute("poolType");
	if(null!=objptype){
		String ptype = objptype.toString();
		System.out.print("---------------------------------------------"+ptype);
		if("2".equals(ptype)){
	%>
    if(!checkRatio()) return;
    rpVal = $('#ratioPercent').val();
	<%		
		}
	}
	%>
	var ecalId_val=$("#ecalId").val();
	editPlan({tradPlanCode:etradPlanCode,tradPlanDesc:etradPlanDesc,Amount:eAmount,calDefId:ecalDefId,poolRatio:rpVal,calId:ecalId_val});
}


function editPlan(param){
	if(!Formstatus){
		$.message("error", "正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "product/editPlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			
			loadPlan({current:1,size:6,tradProdCode:tradProdCode});
			closeEditPlanDiv();
		}
	});
}


function closeEditPlanDiv(){
	$("#editPlanDiv").CloseDiv();
}


//校验险种编辑页面的“共保份额”
function checkRatio(){
	var rp = $.trim($('#ratioPercent').val());
	if(rp==""){
		$.message("error","共保份额不能为空");
		return false;
	}
	var ratioReg = new RegExp("^([1-9][0-9]?|100)$");
	if(!ratioReg.test(rp)){
		$.message("error","请输入0-100的有效整数");
		return false;
	}
	return true;
}		
/**-------------2015年6月5日11:12:56------wangyan---add------↓---------------------*/
function loadChildCal(cal){
	$("#calId").empty();//清空select的option
	var calDef = $('#'+cal).val();
	$.ajax({
		url : "product/getChildCal",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{calDef:calDef},
		success:function(childCalList){
			if($.validate(childCalList))return;
			if(childCalList[0]!=undefined){
				if(childCalList.length>1){
					$("#calIdDiv").show();
					$.each(childCalList,function(i,item){
						$("#calId").append("<option value="+item.calId+">"+item.calIdName+"</option>");
					});
				}else{
					$("#calIdDiv").hide();
					$.each(childCalList,function(i,item){
						$("#calId").append("<option value="+item.calId+">"+item.calIdName+"</option>");
					});
				}
			}
		}
	});
}
function loadeChildCal(cal,calId){
	$("#ecalId").empty();//清空select的option
	var ecalDef = $('#'+cal).val();
	$.ajax({
		url : "product/getChildCal",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{calDef:ecalDef},
		success:function(childCalList){
			if($.validate(childCalList))return;
			if(childCalList[0]!=undefined){
				if(childCalList.length>1){
					$("#ecalIdDiv").show();
					$.each(childCalList,function(i,item){
						if(calId==item.calId){
							$("#ecalId").append("<option value='"+item.calId+"' selected='selected'>"+item.calIdName+"</option>");
						}else{
							$("#ecalId").append("<option value="+item.calId+">"+item.calIdName+"</option>");
						}
					});
				}else{
					$("#ecalIdDiv").hide();
					$.each(childCalList,function(i,item){
						if(calId==item.calId){
							$("#ecalId").append("<option value='"+item.calId+"' selected='selected'>"+item.calIdName+"</option>");
						}else{
							$("#ecalId").append("<option value="+item.calId+">"+item.calIdName+"</option>");
						}
					});
				}
			}
		}
	});
}
/**-------------2015年6月5日11:12:56------wangyan----add-----↑---------------------*/

var minDays = "";// 最小保险期间
var maxDays = "";// 最大保险期间
var calDefIdAll = ""// 全局算法代码
var childCalDefIdAll = "";// 全局算法代码 子代码
var tradPlanCodeFlag = "";//全局交易系统险种
//检验算法方案是否已出单
function checkOpenCalDiv(obj){
	$("#"+obj.id).blur();
	var radioCov = $("input[name='radioProPlan']:checked");
	if(radioCov.val() == undefined) {
		$.message("error","请选择一个险种");
		return;
	}
	var tradPlanCode = radioCov.parent().parent().children("td:eq(1)").html();// 险种代码
	$.ajax({
		url : "product/feeRate/checkOpenCalDiv",
		type : "POST",
		async : false,
		dataType:'json',
		data:{prodCode : tradPlanCode},
		success:function(data) {
			if(data != 0){
				$.dialog({
					type: "warn",
					content:"此产品已出单,确认要修改此算法?",
					onOk: function() {
						openCalDiv(obj);
					}
				});
			}else{
				openCalDiv(obj);
			}
		}
	});
	
}
// 打开算法配置的窗口  加载信息table
function openCalDiv(obj) {
	var radioCov = $("input[name='radioProPlan']:checked");
	var calDefId = radioCov.parent().parent().children("td:eq(6)").html();// 算法代码
	var childCalDefId = radioCov.parent().parent().children("td:eq(9)").html();// 算法代码子代码
	calDefIdAll = calDefId;
	childCalDefIdAll = childCalDefId;
	var tradPlanCode = radioCov.parent().parent().children("td:eq(1)").html();// 险种代码
	tradPlanCodeFlag = tradPlanCode;
	
	if(calDefId == '0000000001' || calDefId == '0000000003' || calDefId == '0000000002' || childCalDefId == '000000000605' || calDefId == '0000000004' || childCalDefId == '000000000606' || '000000000602' == childCalDefIdAll || '000000000603' == childCalDefIdAll) {// 过滤算法
		$.ajax({
			url : "product/feeRate/loadTableInfo",
			type : "POST",
			async : false,
			dataType:'json',
			data:{prodCode : tradProdCode, calDefId : calDefId, childCalDefId : childCalDefId, tradPlanCode : tradPlanCode},
			success:function(data) {
				if(data != null && data != undefined) {
					var tableHtml = getTableHtml(childCalDefId, calDefId, tradPlanCode, data);
					if(tableHtml == undefined) {
						$.message("error","该险种算法配置有误，请检查数据库中对应的算法表或联系管理员");
						return;
					}
					var calTd = $('#calTd');
					calTd.prepend(tableHtml);
					if(calDefId == '0000000001' || calDefId == '0000000003' || childCalDefId == '000000000602' || childCalDefId == '000000000603' || childCalDefId == '000000000605'){
						$("#buttonHidden1").hide();
						$("#buttonHidden2").show();
					}else{
						$("#buttonHidden1").show();
						$("#buttonHidden2").hide();
					}
					$('#editCalDiv').OpenDiv();
				} else {
					$.message("error","产品号不能为空");
					return;
				}
			}
		});
	} else {
		$.message("error","暂不支持，请到数据库进行配置或联系管理员");
		return;
	}
}

var globalAreaInputStr = "";// 驾乘险座位区间表单部分字符串
var globalWholeInputStr = "";// 驾乘险整车/每座表单部分字符串
// 获取加载table回显的数据
function getTableHtml(childCalDefId, calDefId, tradPlanCode, data) {
	if(calDefId == '0000000001' || calDefId == '0000000003') {// 险种天数算法和险种月数算法
		minDays = data.tradProdInst.minDays;
		maxDays = data.tradProdInst.maxDays;
		var feeMap = transListToMap(data, calDefId);// 将List数据转换成Map数据
		var tableStr = creatCalTable(calDefId, tradPlanCode, minDays, maxDays, 4, feeMap);// 加载table中的数据
		return tableStr;
	} else if (calDefId == '0000000002') {// 固定保费算法
		var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' /><input type='hidden' name='calDefId' value='" + calDefId + "' />";
		if(data.feeList.length == 1) {
			tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>保费：</span><input id='fixed' name='fixed' value='" + returnFloat(data.feeList[0].premRate) + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td></tr></tbody></table>";
		} else if (data.feeList.length == 0) {
			tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>保费：</span><input id='fixed' name='fixed' value='' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td></tr></tbody></table>";
		}
		$('#titleDiv').html('固定保费算法');// 设置标题
		return tableStr;
	} else if (calDefId == '0000000004') {// 保额计算保费算法
		var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' /><input type='hidden' name='calDefId' value='" + calDefId + "' />";
		if(data.feeList.length == 0){
			tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>合作伙伴：</span><input id='partnerNo' name='partnerNo' readonly='readonly' style='background-color: #ccc;' value='' ><input class='input_button_5' id='choosePartnerNo' name='choosePartnerNo' type='button' onclick='openPartnerNo(1,this)' value='请选择'/></td>"
			+"<td><span>出单机构：</span><input id='deptNo' name='deptNo' readonly='readonly' style='background-color: #ccc;' value='' /><input class='input_button_5' id='chooseDeptNo' name='chooseDeptNo' type='button' onclick='openChooseDeptNo(1,this)' value='请选择'/></td>"
			+"<td><span>年度费率：</span><input id='yearRate' name='yearRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' value='' /></td>"
			+"</tr></tbody></table>";
		} else {
			tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>合作伙伴：</span><input id='partnerNo' name='partnerNo' readonly='readonly' style='background-color: #ccc;' value='" + data.feeList[0].partnerNo + "' ><input class='input_button_5' id='choosePartnerNo' name='choosePartnerNo' type='button' onclick='openPartnerNo(1,this)' value='请选择'/></td>"
			+"<td><span>出单机构：</span><input id='deptNo' name='deptNo' readonly='readonly' style='background-color: #ccc;' value='" + data.feeList[0].deptNo + "' /><input class='input_button_5' id='chooseDeptNo' name='chooseDeptNo' type='button' onclick='openChooseDeptNo(1,this)' value='请选择'/></td>"
			+"<td><span>年度费率：</span><input id='yearRate' name='yearRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' value='" + data.feeList[0].yearRate + "' /></td>"
			+"</tr></tbody></table>";
		}
		$('#titleDiv').html('保额计算保费算法');// 设置标题
		return tableStr;
	} else if (calDefId == '0000000006') {// 险种通用算法
		if(childCalDefId == '000000000605') {// 驾乘险座位区间
			globalAreaInputStr = "<tr><td align='center' style='width:30%'><input type='hidden' name='useNature'><input type='text' id='natureText' class='input_text' disabled style='width:180px'>&nbsp;<input type='button' class='input_button_2' value='车辆性质' onclick='openUseNatureDiv(this)'></td>"
					+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='minDay' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
					+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='maxDay' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
					+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='premRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
					+ "<td align='center' style='width:10%'><input type='button' onclick='delOneRow(&apos;area&apos;,this)' value='删除'></td></tr>";
			var inputStr = "";
			if(data != null && data.feeList != null && data.feeList.length != 0) {
				for(var i = 0; i < data.feeList.length; i++) {
					inputStr += "<tr><td align='center' style='width:30%'><input type='hidden' name='useNature' value='" + data.feeList[i].COND7 + "'><input type='text' id='natureText' class='input_text' disabled value='" + data.feeList[i].COND7STR + "' title='" + data.feeList[i].COND7STR + "' style='width:180px'>&nbsp;<input type='button' class='input_button_2' value='车辆性质' onclick='openUseNatureDiv(this)'></td>"
						+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='minDay' value='" + data.feeList[i].COND1 + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
						+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='maxDay' value='" + data.feeList[i].COND2 + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
						+ "<td align='center' style='width:20%'><input type='text' class='input_text' style='width:130px' name='premRate' value='" + returnFloat(data.feeList[i].PREM_RATE) + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
						+ "<td align='center' style='width:10%'><input type='button' onclick='delOneRow(&apos;area&apos;,this)' value='删除'></td></tr>";
				}
			} else {
				inputStr = globalAreaInputStr;
			}
			$('#titleDiv').html("险种通用算法（驾乘险座位区间算法）");// 设置标题
			var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' />"
					+ "<input type='hidden' name='calDefId' value='" + calDefId + "' />"
					+ "<input type='hidden' name='childCalDefId' value='" + childCalDefId + "' />"
					+ "<div style='width:100%;overflow:auto;height:297px'><table id='calTable' class='content_table_1'><tbody>"
					+ "<tr><td align='center' style='width:30%'>车辆使用性质</td><td align='center' style='width:20%'>最小座位数</td><td align='center' style='width:20%'>最大座位数</td>"
					+ "<td align='center' style='width:20%'>保费</td><td align='center' style='width:10%'>操作</td></tr>"
					+ inputStr + "<tr><td colspan='5' style='border-bottom-style:none'><div align='right'><input type='image' src='./images/add.png' title='添加一行' onclick='addOneRow(&apos;area&apos;);return false;'></div></td></tr></tbody></table></div>";
			return tableStr;
		} else if ('000000000602' == childCalDefIdAll || '000000000603' == childCalDefIdAll) {// 驾乘险整车/每座算法
			globalWholeInputStr = "<tr><td align='center' style='width:36%'><input type='hidden' name='useNature'><input type='text' id='natureText' class='input_text' disabled style='width:180px'>&nbsp;<input type='button' class='input_button_2' value='车辆性质' onclick='openUseNatureDiv(this)'></td>"
				+ "<td align='center' style='width:27%'><input type='text' class='input_text' style='width:130px' name='dayNum' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
				+ "<td align='center' style='width:27%'><input type='text' class='input_text' style='width:130px' name='premRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
				+ "<td align='center' style='width:10%'><input type='button' onclick='delOneRow(&apos;area&apos;,this)' value='删除'></td></tr>";
			var inputStr = "";
			if(data != null && data.feeList != null && data.feeList.length != 0) {
				for(var i = 0; i < data.feeList.length; i++) {
					inputStr += "<tr><td align='center' style='width:36%'><input type='hidden' name='useNature' value='" + data.feeList[i].COND7 + "'><input type='text' id='natureText' class='input_text' disabled value='" + data.feeList[i].COND7STR + "' title='" + data.feeList[i].COND7STR + "' style='width:180px'>&nbsp;<input type='button' class='input_button_2' value='车辆性质' onclick='openUseNatureDiv(this)'></td>"
						+ "<td align='center' style='width:27%'><input type='text' class='input_text' style='width:130px' name='dayNum' value='" + (data.feeList[i].COND1 == null ? "" : data.feeList[i].COND1) + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
						+ "<td align='center' style='width:27%'><input type='text' class='input_text' style='width:130px' name='premRate' value='" + returnFloat(data.feeList[i].PREM_RATE) + "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'></td>"
						+ "<td align='center' style='width:10%'><input type='button' onclick='delOneRow(&apos;area&apos;,this)' value='删除'></td></tr>";
				}
			} else {
				inputStr = globalWholeInputStr;
			}
			// 设置标题
			if('000000000602' == childCalDefIdAll) {
				$('#titleDiv').html("险种通用算法（驾乘险每座算法）");
			} else if ('000000000603' == childCalDefIdAll) {
				$('#titleDiv').html("险种通用算法（驾乘险整车算法）");
			}
			var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' />"
					+ "<input type='hidden' name='calDefId' value='" + calDefId + "' />"
					+ "<input type='hidden' name='childCalDefId' value='" + childCalDefId + "' />"
					+ "<div style='width:100%;overflow:auto;height:297px'><table id='calTable' class='content_table_1'><tbody>"
					+ "<tr><td align='center' style='width:36%'>车辆使用性质</td><td align='center' style='width:27%'>座位数</td>"
					+ "<td align='center' style='width:27%'>保费</td><td align='center' style='width:10%'>操作</td></tr>"
					+ inputStr + "<tr><td colspan='4' style='border-bottom-style:none'><div align='right'><input type='image' src='./images/add.png' title='添加一行' onclick='addOneRow(&apos;whole&apos;);return false;'></div></td></tr></tbody></table></div>";
			return tableStr;
		} else if(childCalDefId == '000000000606') {//每天保费乘以天数算法
			var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' /><input type='hidden' name='calDefId' value='" + calDefId + "' /><input type='hidden' name='childCalDefId' value='" + childCalDefId + "' />";
			if(data.feeList.length == 0){
				tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>保费：</span><input id='premRate' name='premRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' value='' /></td></tr></tbody></table>";
			} else {
				tableStr += "<table id='calTable' class='content_table_1'><tbody><tr><td><span>保费：</span><input id='premRate' name='premRate' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)' value='" + returnFloat(data.feeList[0].premRate) + "' /></td></tr></tbody></table>";
			}
			$('#titleDiv').html('险种通用算法（每天保费固定乘以天数算法）');// 设置标题
			return tableStr;
		}
	}
}

// 后台返回的List数据转换成前台的Map类型数据
function transListToMap(data, calDefId) {
	var feeList = data.feeList;// 表中已配置的费率信息  用于数据回显
	var map = new Map();
	if(calDefId == '0000000001') {// 天数算法
		for(var i = 0; i < feeList.length; i++) {
			map.put(feeList[i].days, feeList[i].premRate);
		}
	} else if (calDefId == '0000000003') {// 月数算法
		for(var i = 0; i < feeList.length; i++) {
			map.put(feeList[i].months, feeList[i].premRate);
		}
	}
	return map;
}

// 添加一行数据
function addOneRow(type) {
	if(type == 'area') {// 驾乘险座位区间
		$('#calTable tr:last').before(globalAreaInputStr);
		var natureText = $('#calTable tr:last').prev().prev().find('td:eq(0)').find('input[id="natureText"]').val();
		var useNature = $('#calTable tr:last').prev().prev().find('td:eq(0)').find('input[name="useNature"]').val();
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[id="natureText"]').val(natureText);
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[id="natureText"]').attr('title', natureText);
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[name="useNature"]').val(useNature);
		$('#calTable tr:last').prev().find('td:eq(1)').find('input[name="minDay"]').focus();
	} else if (type == 'whole') {// 每座/整车
		$('#calTable tr:last').before(globalWholeInputStr);
		var natureText = $('#calTable tr:last').prev().prev().find('td:eq(0)').find('input[id="natureText"]').val();
		var useNature = $('#calTable tr:last').prev().prev().find('td:eq(0)').find('input[name="useNature"]').val();
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[id="natureText"]').val(natureText);
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[id="natureText"]').attr('title', natureText);
		$('#calTable tr:last').prev().find('td:eq(0)').find('input[name="useNature"]').val(useNature);
		$('#calTable tr:last').prev().find('td:eq(1)').find('input[name="dayNum"]').focus();
	}
}

// 删除一行数据
function delOneRow(type, obj) {
	if(type == 'area') {// 驾乘险座位区间
		obj.closest('tr').remove();
	}
}

// 加载算法table中的数据
function creatCalTable(calDefId, tradPlanCode, minDays, maxDays, columns, feeMap) {
	var tableStr = "<input type='hidden' name='tradPlanCode' value='" + tradPlanCode + "' /><input type='hidden' name='calDefId' value='" + calDefId + "' />";
	var calTitle = "";
	if(calDefId == '0000000001') {
		calTitle = '险种天数算法';
	} else if (calDefId == '0000000003') {
		calTitle = '险种月数算法';
	}
	
	$('#titleDiv').html(calTitle);// 设置标题
	
	tableStr += "<table id='calTable' class='content_table_1'>";
	
	var tdS = "<td>";
	var tdE = "</td>";
	
	countDays = maxDays - minDays + 1;// 根据保险期间算出算法应配的天数
	
	var rows = countDays / columns;
	if(countDays % columns != 0) {
		rows += 1;
	}
	
	if(rows > 10) {// 设置数据表格的高度  大于10行数据时有滚动条
		$('#calDDD').css('height','300px');
	}
	
	var flag = false;
	for(var i = 1; i <= rows; i++) {
		if(!flag) {
			var str = "";
			var thStr = "";
			tableStr += "<thead><tr class='f1'>";
			if(calDefId == '0000000001') {
				thStr = "<th>天数</th>";
			} else if(calDefId == '0000000003') {
				thStr = "<th>月数</th>";
			}
			for(var t = 1; t <= columns; t++) {
				str += thStr + "<th>保费</th>";
			}
			tableStr += str + "</tr></thead><tbody>";
			flag = true;
		}
		tableStr += "<tr>";
		for(var j = 1; j <= columns; j++) {
			if(minDays > maxDays) {
				continue;
			}
			tableStr += tdS + "<span>" + minDays + "</span>" + tdE;
			tableStr += tdS + "<input type='text' id='no" + minDays + "' name='" + minDays + "' value='" +returnFloat(feeMap.get(minDays))+ "' onKeyUp='clearNoNum(event,this)' onBlur='checkNum(this)'>" + tdE ;
			minDays++;
		}
		tableStr += "</tr>";
	}
	tableStr += "</tbody></table>";
	return tableStr;
}

// 保存或修改算法配置
function saveCal() {
	if('0000000001' == calDefIdAll || '0000000003' == calDefIdAll) {// 险种天数算法和险种月数算法
		for(var i = minDays; i <= maxDays; i++) {
			var flag = $('#no' + i);
			var noNum = $.trim(flag.val());
			if("" == noNum) {
				flag.focus();
				$.message("error","保费不能为空");
				return;
			}
			if(regNum(noNum)){
				 $.message("error", "保费格式应保留小数点后两位");
	             flag.focus();
	    		 return;
			}
		}
	} else if ('0000000002' == calDefIdAll) {// 固定保费算法
		var fixed = $.trim($('#fixed').val());
		if(fixed == '') {
			$('#fixed').focus();
			$.message("error","保费不能为空");
			return;
		}
		if(regNum(fixed)){
			$.message("error", "保费格式应保留小数点后两位");
			$('#fixed').focus();
   		 	return;
		}
	} else if('0000000004' == calDefIdAll){//保额计算保费算法
		if($.trim($('#partnerNo').val()).length==0){
			$.message("error", "请选择合作伙伴代码");
			return;
		}
		if($.trim($('#deptNo').val()).length==0){
			$.message("error", "请选择出单机构");
			return;
		}
		if($.trim($('#yearRate').val()).length==0){
			$.message("error", "请填写年度费率");
			return;
		}
	} else if ('0000000006' == calDefIdAll) {// 险种通用算法
		if('000000000606' == childCalDefIdAll) {
			var premRate = $.trim($('#premRate').val());
			if(premRate == ''){//每天保费固定乘以天数算法
				$.message("error", "请填写保费");
				$('#premRate').focus();
				return;
			}
			if(regNum(premRate)){
				$.message("error", "保费格式应保留小数点后两位");
            	$('#premRate').focus();
	   		 	return;
			}
		} else if ('000000000605' == childCalDefIdAll) {// 驾乘险座位区间算法
			var inputNum = $('#calTable tr').length;
			if(inputNum < 3) {
				$.message("error", "没有任何数据");
				return;
			}
			var flag = true;
			$('#calTable input[name="useNature"]').each(function() {
				if('' == $(this).val() || $(this).val() == null) {
					$(this).focus();
					$.message("error","车辆使用性质不能为空");
					flag = false;
					return flag;
				}
			});
			$('#calTable input[name="minDay"]').each(function() {
				if('' == $(this).val() || $(this).val() == null) {
					$(this).focus();
					$.message("error","最小座位数不能为空");
					flag = false;
					return flag;
				}
			});
			$('#calTable input[name="maxDay"]').each(function() {
				if('' == $(this).val() || $(this).val() == null) {
					$(this).focus();
					$.message("error","最大座位数不能为空");
					flag = false;
					return flag;
				}
			});
			$('#calTable input[name="premRate"]').each(function() {
				if('' == $.trim($(this).val())) {
					$(this).focus();
					$.message("error","保费不能为空");
					flag = false;
					return flag;
				}
				if(regNum($.trim($(this).val()))){
					$.message("error", "保费格式应保留小数点后两位");
	                $(this).focus();
	                flag = false;
					return flag;
				}
			});
			if(flag == false) {
				return;
			}
		} else if ('000000000602' == childCalDefIdAll || '000000000603' == childCalDefIdAll) {// 驾乘险整车/每座算法
			var inputNum = $('#calTable tr').length;
			if(inputNum < 3) {
				$.message("error", "没有任何数据");
				return;
			}
			var flag = true;
			$('#calTable input[name="useNature"]').each(function() {
				if('' == $(this).val() || $(this).val() == null) {
					$(this).focus();
					$.message("error","车辆使用性质不能为空");
					flag = false;
					return flag;
				}
			});
			$('#calTable input[name="premRate"]').each(function() {
				if('' == $.trim($(this).val())) {
					$(this).focus();
					$.message("error","保费不能为空");
					flag = false;
					return flag;
				}
	            if(regNum($.trim($(this).val()))){
	            	$.message("error", "保费格式应保留小数点后两位");
	                $(this).focus();
	                flag = false;
					return flag;
	             }
			});
			if(flag == false) {
				return;
			}
		}
	}
	
	var arr = JSON.stringify($("#calForm").serializeArray());
	$.openLoading();
	$.ajax({
		url : "product/feeRate/saveCal",
		type : "POST",
		async : false,
		dataType:'json',
		contentType:"application/json",
		data:arr,
		success:function(data) {
			if(true == data.result) {
				$.closeLoading();
				$.message("success","算法配置成功");
				closeCalDiv();
			} else {
				$.closeLoading();
				$.message("error","系统异常，算法配置失败");
				return;
			}
		}
	});
	
}

//点击请选择打开合作伙伴div
function openPartnerNo(pageIndex,obj){
	$('#channelCode').val('');
	$('#channelName').val('');
	$("#"+obj.id).blur();
	queryTradPartners(pageIndex);
}
//查询 合作伙伴
function queryTradPartners(pageIndex){
	$("#BigDiv2").remove();
	var size = 8;
	var channelCode = $.trim($('#channelCode').val());
	var channelName = $.trim($('#channelName').val());
	$.openLoading();
	$.ajax({
		url : "product/feeRate/queryChannelInfoOfLife",
		type : 'POST',
		async : true,
		data:{
			pageIndex:pageIndex,
			size:size,
			channelCode:channelCode,
			channelName:channelName
		},
		dataType:'json',
		success:function(page){
			$.closeLoading();
			if($.validate(page))return;
			var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
			var fieldNames = "channelCode,channelName";
			var tableContent = creatTable1(fieldNames,page,radioObj);
			var tableObj = $("#channelInfoTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage2(pageIndex,6,page.maxPage,"16");
			var pageDIV = $("#channelInfoPageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			
			$("#channelInfoDiv").OpenDiv2();
		}
	});
}
//点击“确定”按钮，选择合作伙伴
function choosePartner(){
	var selectedPartner = $("input[name='partnerradio']:checked");
	if(selectedPartner.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var selectedPartnerNo = selectedPartner.parent().parent().children(" td:eq(1)").html();
	$('#partnerNo').val(selectedPartnerNo);
	
	closeCurrentDIV('channelInfoDiv');
	//清空出单机构 
	$('#deptNo').val('');
}
//关闭窗口
function closeCurrentDIV(obj){
	if(obj == 'channelInfoDiv' || obj == 'deptDiv'){
		$("#"+obj).CloseDiv2();
	}else{
		$("#"+obj).CloseDiv();
	}

}

//点击选择打开出单机构div
function openChooseDeptNo(pageIndex,obj){
	if($.trim($('#partnerNo').val()).length==0){
		$.message("error", "请先选择合作伙伴");
		return;
	}
	$('#deptcode').val('');
	$('#deptcnname').val('');
	$("#"+obj.id).blur();
	queryCoreDept(pageIndex);
}
//调用拼接参数的方法，并执行查询
function queryCoreDept(pageIndex){
	var size = 8;
	var code = $('#deptcode').val();
	var name = $('#deptcnname').val();
	var pno = $('#partnerNo').val();
	queryAllDepts({size:size,pageIndex:pageIndex,deptCode:code,deptCNname:name,channelCode:pno});
}

/*-----------------------------------核保规则分配开始---add by zkm-----------------------------------*/
var map = new Map();

//统一 关闭  窗口
function closeAuwConfigDiv(obj){
	map.clear();
	$("#auwConfigsDivTable").find("tr").each(function(){
		$(this).children("td:eq(0)").find("input[name='auwarr']").prop("checked",false);
	});
    $("#"+obj).CloseDiv();
}

// 打开产品窗口
function openAuwConfigDiv(pageIndex){
	$.ajax({
		url : "<%=path%>/product/feeRate/queryAuwConfigsByProd",
		type : 'POST',
		async : false,
		data:{"tradProdCode":tradProdCode},
		dataType:'json',
		success:function(data){
			if(data[0]!=undefined){	
				map.clear();//清空备份map
				$.each(data,function(i,item){
		        	var obj = new Object();
		        	obj.id = item.configId;
		        	map.put(obj.id,obj);
				})
			}
		}
	});
	queryAuwConfigs(pageIndex);
}
//查询机构
function queryAllDepts(param){
	$("#BigDiv2").remove();
	$.openLoading();
	$.ajax({
		url : "product/feeRate/loadCoreDept",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(deptPage){
			$.closeLoading();
			if($.validate(deptPage))return;

				var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
				var fieldNames = "deptCode,deptCNname";
				var tableContent = creatTable1(fieldNames,deptPage,radioObj);
				var tableObj = $("#deptTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage2(param.pageIndex,6,deptPage.maxPage,"18");
				var pageDIV = $("#deptPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
				$("#deptDiv").OpenDiv2();
			}
	});
}
//点击“确定” ，选择 出单机构
function chooseDept(){
	var selectedDept= $("input[name='deptradio']:checked");
	if(selectedDept.length==0){
		$.message("error", "请选择一个出单机构");
		return;
	}
	var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
	$('#deptNo').val(deptCode);
	closeCurrentDIV('deptDiv');
}


// 调用拼接参数的方法，并执行查询
function queryAuwConfigs(pageIndex){
	var size = 10;
	// 翻页时会用到如下代码
	var selectedAuw = $("input[name='auwarr']:checked");
	if(selectedAuw.length!=0){
		selectedAuw.each(function(i){
			var obj = new Object();
			obj.id= $(this).parent().parent().children(" td:eq(1)").html();
			
			map.put(obj.id,obj);
		});
	}
	// 翻页时用如上代码
	loadAuwConfig({size:size,pageIndex:pageIndex,tradProdCode:tradProdCode});
}

//配置代理信息
function loadAuwConfig(param){
	$.openLoading();
	
	$.ajax({
		url : "<%=path%>/product/feeRate/queryAuwConfigsByPage",
		type : 'POST',
		async : false,
		data:param,
		dataType:'json',
		success:function(configPage){
			$.closeLoading();
			if($.validate(configPage))return;
				var checkboxObj ="<input name='auwarr' type='checkbox'>";
				var fieldNames = "configId,configDesc";
				var tableContent = creatTable1(fieldNames,configPage,checkboxObj,null);
				var tableObj = $("#auwConfigsDivTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage4(param.pageIndex,6,configPage.maxPage,"59");
				var pageDIV = $("#userRoleDivPage");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
				$("#auwConfigsDivTable").find("tr").each(function(){
					var id = $(this).children(" td:eq(1)").html();
					if(map.containsKey(id)){
						$(this).addClass("table_highlighter");
						$(this).children("td:eq(0)").find("input[name='auwarr']").prop("checked",true);
					}else{
						$(this).removeClass("table_highlighter");
						$(this).children("td:eq(0)").find("input[name='auwarr']").prop("checked",false);
					}
				});
				checkAll();
				bindradioSS();
				$('#auwConfigDiv').OpenDiv();
		}
	});
}

function checkAll(){
	var flag = false;
	$("#auwConfigsDivTable tbody").find("tr").each(function(){
		var id = $(this).children(" td:eq(1)").html();
		if(!$(this).children("td:eq(0)").find("input[name='auwarr']").prop("checked")){
			flag = true;//如果有未选择的
		}
	});
	if(flag){
		$("#auwConfigCheckAll").prop("checked",false);
	}else{
		$("#auwConfigCheckAll").prop("checked",true);
	}
}

function saveAuwConfig(){
	var selectedAuw = $("input[name='auwarr']:checked");
	var auwConfigListStr ='';
	if(selectedAuw.length!=0){
		selectedAuw.each(function(i){
			var obj = new Object();
			obj.id= $(this).parent().parent().children("td:eq(1)").html();
			map.put(obj.id,obj);
		});
	}
	if(!map.isEmpty()){
		var auwConfigList = new Array();
		for(i in map.keys()){
	        var key = map.keys()[i];
	        auwConfigList.push(map.get(key));
	    }
		auwConfigListStr=JSON.stringify(auwConfigList);
	}
	updateAuwConfig({tradProdCode:tradProdCode,auwConfigListStr:auwConfigListStr});
	closeAuwConfigDiv('auwConfigDiv');
}

//执行更新
function updateAuwConfig(param){
	$.openLoading();
	$.ajax({
		url : "<%=path%>/product/feeRate/setAuwConfigsToProd",
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(data){
			$.closeLoading();
			if($.validate(data))return;
		}
	});
}

// 绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
function bindradioSS(){
	$("input[name='auwarr']").click(function(){
		var id= $(this).parent().parent().children(" td:eq(1)").html();
		if($(this).prop("checked")){//选中
			$(this).parent().parent().addClass("table_highlighter");
			var obj = new Object();
			obj.id =id;
			map.put(obj.id,obj);
			checkAll();
		}else{//取消选中
			$(this).parent().parent().removeClass("table_highlighter");
			$(this).prop("checked",false);
			map.remove(id);
			$("#auwConfigCheckAll").prop("checked",false);
		}
	});
	$("#auwConfigCheckAll").click(function(){
		if($(this).prop("checked")){//选中
			$("#auwConfigsDivTable tbody tr").each(function() {
				$(this).find("input[name='auwarr']").prop("checked",true);
				$(this).addClass("table_highlighter");
				var obj = new Object();
				var id= $(this).children(" td:eq(1)").html();
				obj.id =id;
				map.put(obj.id,obj);
			});
		}else{//取消选中
			$("#auwConfigsDivTable tbody tr").each(function() {
				$(this).removeClass("table_highlighter");
				$(this).find("input[name='auwarr']").prop("checked",false);
				var id= $(this).children(" td:eq(1)").html();
				map.remove(id);
			});
		}
	});
}
/*-----------------------------------核保规则分配结束---add by zkm-----------------------------------*/
	//算法模板下载
	function calTemplateDownLoad(){
		if('0000000001' == calDefIdAll || '0000000003' == calDefIdAll || '000000000602' == childCalDefIdAll || '000000000603' == childCalDefIdAll || '000000000605' == childCalDefIdAll){
			window.location.href='<%=path%>/product/feeRate/calTemplateDownLoad?calDefId='+calDefIdAll+'&childCalDefId='+childCalDefIdAll;
		}else{
			$.message("error","不存在相应算法模板");
		}
	}
	//算法excel数据导入
	function calTemplateImport(){
		$("#calTemplateImportDiv").css({"width":"50%","height":"135px"});
		$("#chooseReconciliationFileForm").css("display","block");
		$("#calTemplateImportDiv").OpenDiv2();
	}
	//关闭批量更新Div
	function closeCalTemplateImportDiv(){
		$("#calTemplateImportDiv").CloseDiv2();
	}
	//导入数据
	function reconciliationFileChose(){
		var reconciliationFile=$("#reconciliationFile").val();
		if(reconciliationFile.length == 0){
			$.message("error","请先选择更新文件");
			return;
		}
		if(reconciliationFile.substr(reconciliationFile.lastIndexOf(".")) != ".xls"){
			$.message("error", "必须选择xls格式的文件");
			return;
		}
		$.ajaxFileUpload({
		    url:'<%=path%>/product/feeRate/calTemplateImport?calDefId='+calDefIdAll+'&tradProdCode='+tradProdCode+'&childCalDefId='+childCalDefIdAll,
		    fileElementId :'reconciliationFile',//file控件id
		    dataType: 'json',
		    success : function (data){
		    	if(data.result=="error"||data.result=="fail"){
		        	$.dialog({
		    			width: 358,
		    			top:40,
		    			modal:true,
		    			Close:true,
		    			cancel:null,
		    			content: data.message
		    		});
		        	return;
		      }else if(data.result=="success"){
		    	  closeCalTemplateImportDiv();
		    	  var tableHtml = getTableHtml(childCalDefIdAll,calDefIdAll, tradPlanCodeFlag, data.map);
					if(tableHtml == undefined) {
						$.message("error","该险种算法配置有误，请检查数据库中对应的算法表或联系管理员");
						return;
					}
					var calTd = $('#calTd');
					calTd.empty();
					calTd.prepend(tableHtml);
                }
		    }
		    
		});			
	     
	}

/*-----------------------------------车辆使用性质分配开始---add by zkm-----------------------------------*/
var map1 = new Map();
var trObj = "";

function openUseNatureDiv(obj) {
	$.openLoading();
	trObj = obj;
	$.ajax({
		url : "<%=path%>/product/feeRate/queryUseNatureByPage",
		type : 'POST',
		async : false,
		dataType : 'json',
		data : {pageIndex:1},
		success:function(configPage) {
			$.closeLoading();
			if($.validate(configPage)) {
				return;	
			}
			var checkboxObj ="<input name='naturearr' type='checkbox'>";
			var fieldNames = "codeName,code";
			var tableContent = creatTable1(fieldNames,configPage,checkboxObj,null);
			var tableObj = $("#useNatureDivTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			checkAllForUseNature();
			bindradioSSS();
			$('#useNatureDiv').OpenDiv2();
		}
	});
}

// 保存车辆使用性质
function saveUseNature() {
	var natureNames = map1.values();// 已选择的车辆性质name （数组）
	var natureValues = map1.keys();// 已选择的车辆性质code （数组）
	var useNature = $(trObj).parent("td:eq(0)").find("input[id='natureText']");
	useNature.val(natureNames);
	useNature.attr('title', natureNames)
	var natureValueStr = '';
	if(natureValues.toString().indexOf(",") != -1) {
		natureValueStr = ',' + natureValues.toString() + ',';
	} else {
		natureValueStr = natureValues.toString();
	}
	var useNatureValue = $(trObj).parent("td:eq(0)").find("input[name='useNature']").val(natureValueStr);
	closeUseNatureDiv('useNatureDiv');
}

// 车辆使用性质窗口关闭
function closeUseNatureDiv(obj) {
	map1.clear();
	$("#useNatureDivTable").find("tr").each(function() {
		$(this).children("td:eq(0)").find("input[name='naturearr']").prop("checked",false);
	});
    $("#"+obj).CloseDiv2();
}

// 全选操作
function checkAllForUseNature() {
	var flag = false;
	$("#useNatureDivTable tbody").find("tr").each(function() {
		if(!$(this).children("td:eq(0)").find("input[name='naturearr']").prop("checked")) {
			flag = true;//如果有未选择的
		}
	});
	if(flag) {
		$("#useNatureCheckAll").prop("checked",false);
	} else {
		$("#useNatureCheckAll").prop("checked",true);
	}
}

//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
function bindradioSSS() {
	$("input[name='naturearr']").click(function() {
		var id = $(this).parent().parent().children("td:eq(2)").html();
		var name = $(this).parent().parent().children("td:eq(1)").html();
		if($(this).prop("checked")) {//选中
			$(this).parent().parent().addClass("table_highlighter");
			map1.put(id, name);
			checkAllForUseNature();
		} else {//取消选中
			$(this).parent().parent().removeClass("table_highlighter");
			$(this).prop("checked",false);
			map1.remove(id);
			$("#useNatureCheckAll").prop("checked",false);
		}
	});
	$("#useNatureCheckAll").click(function() {
		if($(this).prop("checked")){//选中
			$("#useNatureDivTable tbody tr").each(function() {
				$(this).find("input[name='naturearr']").prop("checked",true);
				$(this).addClass("table_highlighter");
				var id = $(this).children("td:eq(2)").html();
				var name = $(this).children("td:eq(1)").html();
				map1.put(id, name);
			});
		} else {//取消选中
			$("#useNatureDivTable tbody tr").each(function() {
				$(this).removeClass("table_highlighter");
				$(this).find("input[name='naturearr']").prop("checked",false);
				var id = $(this).children(" td:eq(2)").html();
				map1.remove(id);
			});
		}
	});
}

//打开算法定义详情
function openCaldefDetail(){
	$("#caldefDiv").OpenDiv();
}
//关闭算法定义详情
function closeCaldefDiv(obj) {
    $("#"+obj).CloseDiv();
}
/*-----------------------------------车辆使用性质分配结束---add by zkm-----------------------------------*/
</script>
<style>
	.input_text {
	padding-left: 3px;
	}
	</style>
</head>
<body>
<div class="right">
	      <div class="current">
	           <table class="current_table_1">
	              <tbody>
		              <tr>
		                <td><img src="./images/current_1.jpg"></td>
		                  <td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
			                  <span style=" color:#136bab; ">产品管理
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>险种添加
			                  </span>
		                  </td>
		                  <td><img src="./images/current_3.jpg"></td>
		              </tr>
	           	  </tbody>
	           </table>
	      </div>
	      <div>
			<form id="inputForm" >
			<table class="table_05">
	              <tbody>
		    		  <tr>
 		              	<td style="line-height:23px;">
 		              		<font color="#3876bf"><b>产品代码：</b></font> ${tradProdCode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#3876bf"><b>产品描述：</b></font>${tradProdDesc}
 		              	</td>
		              </tr>
	           	  </tbody>
	         </table> 
	        <table class="table_05">
	              <tbody>
		              <tr>
		                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">险种添加</td>
		              </tr>
		    		  <tr>
		                  <th width="25%">险种模板名称：</th>
		                  <td width="30%"><input name="insnme" id="insnme" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span>&nbsp;<input type="button"  class="input_button_2" id="searchBtn" value="选择模板" onClick="openPlanDiv(this)"/></td>
		                  <th width="25%">交易系统险种名称：</th>
		                  <td width="20%"><input id="tradPlanDesc" type="text" maxlength="100" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <tr>
		                  <th>业务系统险种代码：</th>
		                  <td><input name="planCode" id="planCode" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		                  <th>业务系统险种版本号：</th>
		                  <td><input name="instCode" id="instCode" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <tr>
		                  <th>产品版本号：</th>
		                  <td><input name="prodInstCode" id="prodInstCode" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		                  <th>主附险标志：</th>
		                  <td><input name="insType" id="insType" type="text" readonly="true" style=" background-color: #ccc;" class="input_text"><span class="red">*</span></td>
		              </tr>
		              <tr  id="lastTr">
		                  <th><img alt="" src="<%=path%>/images/caldef.jpg" onclick="openCaldefDetail();">算法定义：</th>
		                  <td>
		                  	<div style="float: left;">
			                  	<select name="calDefId" id="calDefId" onchange="checkCalDef('calDefId','Amount')" class="select_1" style="visibility: visible;width:250px;">
			                  	 <c:forEach var="trad" items="${tradCalDef}">
			                  		<option value="${trad.calDefId}">${trad.calDefName}</option>
			                  	 </c:forEach>
			                  	</select><span class="red">*</span>
		                  	</div>
		                  	<div id="calIdDiv" style="float: left;display:none;">
		                  		<select name="calId" id="calId"  class="select_1" style="visibility: visible;width:150px;">
			                  	 
			                  	</select>
		                  	</div>
		                  </td>
		                  <th>险种保额(保留2位小数)：</th>
		                  <td><input name="Amount" id="Amount" maxlength="10" type="text" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		              </tr>
	           	  </tbody>
	         </table> 
	         <div align="center">
	             <input class="input_button_1" name="" type="button" onclick="add()" value="保存">&nbsp;&nbsp;
		         <input class="input_button_1" name="" type="button" onclick="vreset()"value="重置">
	         </div>
	         </form>
	      </div>
	      
	      <input class="input_button_2" id="openCovDiv" name="" type="button" onclick="openCovDiv(this)" value="配置责任">
	      <input class="input_button_2" id="openCalDiv" name="" type="button" onclick="checkOpenCalDiv(this)" value="算法配置">
	      <input class="input_button_2" id="openAuwConfigDiv" name="" type="button" onclick="openAuwConfigDiv(1)" value="核保规则">
	      <!-- 险种列表 -->
	      <div style="margin-top: 5px;">
	         <table class="table_02" id="ProdPlan" align="center" >
				<tbody>
					<tr>
						   <td colspan="6" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:27px;height:27px; background-image:url(images/centent_1.jpg)">&nbsp;已添加险种列表</td>
					</tr>
					<tr>
						<td>
							<table id="ProdPlanTable" class="content_table_1">
								<thead>
									<tr class="f1">
									   <th style="width:5%">选择</th>
					                   <th style="width:16%">交易系统险种代码</th>
								       <th style="width:23%">交易系统险种名称</th>
								       <th style="width:10%">险种保额</th>
								       <th style="width:16%">业务系统险种代码</th>
								       <th style="width:22%">业务系统险种名称</th>
								       <th style="width:8%">操作</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="ProdPlanpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
	      </div>     
</div>

		<!--添加模板 DIV-->
  		<div id="addPlanDiv" style="display:none;width:80%;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			
			<div style='width:100%;height:20px;line-heighe:20px;background-color:#A4BDE3'>
					<table class="table_title">
						<tr>
						<td width="70px"></td>
						<td width="100%" id="interfaceName"></td>
						<td width="40px" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closePlanDiv()"/></td>
						</tr>
					
					</table>
			</div>
			
			<table class="table_02" id="addPlanTable"  align="center" >
				<tbody>
					<tr>
						<td>
							<table id="productPlanTable"  class="content_table_1">
								<thead>
									<tr class="f1">
					                  <th style="width:5%">选择</th>
					                  <th style="width:25%">险种代码</th>
					                  <th style="width:20%">险种版本号</th>
					                  <th style="width:50%">业务系统险种名称</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="productPlanpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			 <input class="input_button_3" name="" type="button" onclick="choosePlan()" value="确定">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closePlanDiv()"  value="取消">
			</div>
	</div>
	
	<!--添加责任保额-->
  		<div id="editCovDiv" style="display:none;width:90%;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
			
			<div style='width:100%;height:20px;line-heighe:20px;background-color:#A4BDE3'>
					<table class="table_title">
						<tr>
						<td width="70px"></td>
						<td width="100%" id="interfaceName"></td>
						<td width="40px" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCovDiv()"/></td>
						</tr>
					
					</table>
			</div>
			
			<form id="covForm" >
			<table class="table_02" id="addCovDivTable" align="center" >
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1">
								<thead>
									<tr class="f1">
									  <th style="width:10%">核心责任代码</th>
									  <th style="width:18%">核心责任名称</th>
									  <th style="width:11%">出单责任代码</th>
					                  <th style="width:15%">出单责任名称</th>
					                  <th style="width:28%">保额</th>
					                  <th style="width:14%">免赔额(保留2位小数)</th>
					                  <th style="width:14%">赔付比例（%）</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="coverageTablepageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			 <input class="input_button_3" name="" type="button" onclick="saveCov()" value="保存">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closeCovDiv()"  value="取消">
			</div>
			</form>
	</div>
	<!--   	添加模板 DIV 默认隐藏-->
	<div id="editPlanDiv"  style="display:none;width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditPlanDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">交易系统险种名称：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input name="etradPlanDesc" id="etradPlanDesc" type="text" class="input_text"><span class="red">*</span></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">险种保额：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input name="eAmount" id="eAmount" type="text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)" class="input_text"></td>
					                </tr>
					                <tr> 
					                  <td width="40%" style="text-align:right;border-right:0px;">算法定义：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left">
					                  	<div>
						                  	<select name="ecalDefId" id="ecalDefId" onchange="checkeCalDef('ecalDefId','eAmount')" class="select_1" style="visibility: visible;width:250px;">
						                  	 <c:forEach var="trad" items="${tradCalDef}">
						                  		<option value="${trad.calDefId}">${trad.calDefName}</option>
						                  	 </c:forEach>
						                  	</select><span class="red">*</span>
					                  	</div>
					                  	<div id="ecalIdDiv" style="float: left;display:none;margin-top: 5px;s"> 
						                  	<select name="ecalId" id="ecalId" class="select_1" style="visibility: visible;width:250px;">
						                  	 
						                  	</select>
					                  	</div>
					                  </td>
									</tr>
									<%
									Object obj = request.getAttribute("poolType");
									if(null!=obj){
										String ptype = obj.toString();
										if("2".equals(ptype)){
									%>
									<tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">共保份额：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="ratioPercent" type="text" onchange="checkRatio()" class="input_text">&nbsp;<span style='font-size:16px;vertical-align:middle;'>%</span><span class="red">*</span></td>
					                </tr>
									<%		
										}
									}
									%>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveEditPlan()" value="确定">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeEditPlanDiv()" value="取消">
			</div>
	</div>
	
	<!-- 算法配置Div -->
	<div id="editCalDiv" style="display:none;width:90%;">
		<input type="hidden" id="row_num" name="row_num" value="0"/>
		<div style='width:100%;height:20px;line-heighe:20px;background-color:#A4BDE3'>
			<table class="table_title">
				<tr>
					<td width="70px"></td>
					<td width="100%" id="interfaceName" align="center"><h3 id="titleDiv"></h3></td>
					<td width="40px" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCalDiv()"/></td>
				</tr>
			</table>
		</div>
		
		<div style="width:100%;">
			<form id="calForm">
				<div id="calDDD" style="width:100%;overflow:auto;">
					<table id="addCovDivTable" class="table_20" align="center">
						<tbody>
							<tr>
								<td id="calTd">
								</td>
							</tr>
						</tbody>
					</table>
				</div>
				<div align="center" id="buttonHidden1">
					<input class="input_button_3" name="" type="button" onclick="saveCal()" value="保存">&nbsp;&nbsp;
			        <input class="input_button_3" name="" type="button" onclick="closeCalDiv()" value="取消">
				</div>
				<div style="display: none;" id="buttonHidden2">
					<table style="width:100%;">
						<tr>
							<td width="40%">
								&nbsp;&nbsp;<input class="input_button_2" name="" type="button" onclick="calTemplateDownLoad()" value="模板下载">
								&nbsp;<input class="input_button_2" name="" type="button" onclick="calTemplateImport()" value="数据导入">
							</td>
							<td width="60%">
								<input class="input_button_3" name="" type="button" onclick="saveCal()" value="保存">&nbsp;&nbsp;
			        			<input class="input_button_3" name="" type="button" onclick="closeCalDiv()" value="取消">
							</td>
						</tr>
					</table>
				</div>
			</form>
		</div>
	</div>
	
	<!--选择 合作伙伴 div 默认隐藏-->
  	<div id="channelInfoDiv" style="display:none;width:80%;">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height: 20px;'>
				<tr>
				<td width="10%"></td>
				<td width="80%" id="interfaceName"></td>
				<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('channelInfoDiv')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">&nbsp;&nbsp;
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('channelInfoDiv')" class="input_button_3"/>
		</div>
	</div>

	<!--选择机构 DIV 默认隐藏-->
	<div id="deptDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('deptDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 出单机构代码：<input name="txt3"  id="deptcode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 出单机构名称：<input name="txt3" id="deptcnname"  type="text" class="input_text" value="">
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCoreDept(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="deptTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:45%">出单机构代码</th>
			                  <th style="width:50%">出单机构名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="deptPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('deptDiv')" class="input_button_3"/>
		</div>
	</div>
	
	<!-- 配置产品核保规则的Div -->
	<div id="auwConfigDiv" style="display:none;width:70%;">
		<div class="table_title_div">
			<table class="table_title" style="width:98%;height:20px;">
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeAuwConfigDiv('auwConfigDiv')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="width:98%;" align="center">
			<tr>
				<td>
					<div style="height:300px">
						<table id="auwConfigsDivTable"  class="content_table_1">
							<thead>
								<tr class="f1">
									<th style="width:5%"><input id="auwConfigCheckAll" type="checkbox"></th>
									<th style="width:15%">核保规则ID</th>
									<th style="width:80%">核保规则描述</th>
				              	</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
					<div id="userRoleDivPage" class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
			<input type="button" id="saveRoleBtn" value="保存" onclick="saveAuwConfig()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeAuwConfigDiv('auwConfigDiv')" class="input_button_3"/>
		</div>
	</div>
		
	<!-- excel导入界面-->
	<div id="calTemplateImportDiv"  style="display:none;width:50%;height: 30%;background-color:#f6f7f9;">
        	<div class="table_title_div"">
				<table class="table_title" style="width:100% ;height: 20px;">
					<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeCalTemplateImportDiv()"/></td>
					</tr>
				</table>
			</div>
			
	   		<form id="chooseReconciliationFileForm" action="" method="POST" enctype="multipart/form-data" >
	     		<table class="table_02" style="width: 92%" align="center">
	     			<tr>
	     				<td style="padding:25px 20px ">
	     					请选择批量更新文件：<input type="file" id="reconciliationFile" name="reconciliationFile"/>
	        				<input type="button" class="input_button_1" value="导入" onClick="reconciliationFileChose()"/>
	     				</td>
	     			</tr>
	     		</table>
	     	</form>
        </div>
        
	<!-- 选择车辆使用性质Div -->
	<div id="useNatureDiv" style="display:none;width:50%;">
		<div class="table_title_div">
			<table class="table_title" style="width:98%;height:20px;">
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeUseNatureDiv('useNatureDiv')"/></td>
				</tr>
			</table>
		</div>
		<table class="table_02" id="table" style="width:98%;" align="center">
			<tr>
				<td>
					<div style="height:135px">
						<table id="useNatureDivTable"  class="content_table_1">
							<thead>
								<tr class="f1">
									<th style="width:5%"><input id="useNatureCheckAll" type="checkbox"></th>
									<th style="width:45%">车辆使用性质描述</th>
									<th style="width:50%">车辆使用性质ID</th>
				              	</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</td>
			</tr>
		</table>
		<div align="center">
			<input type="button" id="saveUseNatureBtn" value="确定" onclick="saveUseNature();" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeUseNatureDiv('useNatureDiv');" class="input_button_3"/>
		</div>
	</div>
	
	<!-- 算法定义详情说明 -->
	<div id="caldefDiv" style="display:none;width:90%;">
		<div class="table_title_div">
			<table class="table_title" style="width:98%;height:20px;">
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName" align="center"><h3>险种算法</h3></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCaldefDiv('caldefDiv')"/></td>
				</tr>
			</table>
		</div>
		<div style="width:99%;height:325px;">
			<table class="table_02" id="table" align="center">
				<tr><th style='width:27%;' colspan='2'>算法名称</th><th style="width:38%;">算法描述</th><th style="width:35%;">算法配置</th></tr>
				<tr><td style='text-align:center;' colspan='2'>险种天数算法</td><td style="text-align:left;">&nbsp;每天对应不同的保费</td><td style="text-align:left;">&nbsp;配置天数、保费数据</td></tr>
				<tr><td style='text-align:center;' colspan='2'>险种月数算法</td><td style="text-align:left;">&nbsp;每月对应不同的保费</td><td style="text-align:left;">&nbsp;配置月数、保费数据</td></tr>
				<tr><td style='text-align:center;' colspan='2'>保额计算保费</td><td style="text-align:left;">&nbsp;险种保额*费率的保费</td><td style="text-align:left;">&nbsp;配置出单机构、合作伙伴、固定费率数据</td></tr>
				<tr><td style='text-align:center;' rowspan='2'>固定保费算法</td><td>固定保费(计算人数)</td><td style="text-align:left;">&nbsp;固定保费*人数,与录入被保人数有关</td><td style="text-align:left;">&nbsp;配置固定保费数据</td></tr>
				<tr><td>固定保费(不计算人数)</td><td style="text-align:left;">&nbsp;固定保费,与录入被保人数无关</td><td style="text-align:left;">&nbsp;配置固定保费数据</td></tr>
				<tr><td style='text-align:center;' rowspan='5'>险种通用算法</td><td>驾乘险算法1(每座)</td><td style="text-align:left;">&nbsp;不同车辆使用性质、不同座位数对应不同的保费</td><td style="text-align:left;">&nbsp;配置车辆使用性质、座位数、保费数据</td></tr>
				<tr><td>驾乘险算法2(整车)</td><td style="text-align:left;">&nbsp;不同车辆使用性质、不同车辆类型、不同座位数对应不同的保费</td><td style="text-align:left;">&nbsp;配置车辆使用性质、车辆类型、座位数、保费数据</td></tr>
				<tr><td>驾乘险算法3(座位区间)</td><td style="text-align:left;">&nbsp;不同车辆使用性质、不同区间座位数对应不同的保费</td><td style="text-align:left;">&nbsp;配置车辆使用性质、最小座位数、最大座位数、保费数据</td></tr>
				<tr><td>天数区间算法(去哪儿网)</td><td style="text-align:left;">&nbsp;不同区间座位数对应不同的保费</td><td style="text-align:left;">&nbsp;配置最小座位数、最大座位数、保费数据</td></tr>
				<tr><td>每天保费固定乘以天数算法</td><td style="text-align:left;">&nbsp;固定保费*投保天数,与投保天数有关</td><td style="text-align:left;">&nbsp;配置固定保费数据</td></tr>
				<tr><th colspan='4'>注：除《险种通用算法》中“天数区间算法(去哪儿网)”和“关于车辆类型的驾乘险算法2(整车)”不支持界面录入外,其余都支持界面录入</th></tr>
			</table>
		</div>
		<div align="center">
			<input type="button" value="关闭" onclick="closeCaldefDiv('caldefDiv')" class="input_button_3"/>
		</div>
	</div>
</body>
</html>